# -*- coding: utf-8 -*-
import os
from liberHook.BaseHook import BaseHook
from liberLibs.dccLibs import Maya


class Hook(BaseHook):
    def __init__(self, library, directory, ext, start, end):
        BaseHook.__init__(self, library, directory, ext, start, end)

    def execute(self):
        if not Maya.load_plugin("gpuCache.mll"):
            self.append_error("Load gpuCache.mll failed.")
            return
        gpu_file_name = "%s/%s.abc" % (self.location, self.name)
        if not os.path.isfile(gpu_file_name):
            self.append_error("%s is not an exist file." % gpu_file_name)
            return
        gpu_shape_name = "%sGpuShape" % self.name
        gpu_name = "%s_gpu" % self.name
        gpu_file_name = gpu_file_name.replace("\\", "/")
        Maya.import_gpu_cache(gpu_shape_name, gpu_name, gpu_file_name)
